use anyhow::Result;
use log::info;
use std::cell::RefCell;

thread_local! {
    pub static GLOBAL_HOLDER :RefCell<Holder> =RefCell::new(Holder(User::default()));
}

pub fn run() -> Result<()> {
    for i in 1..11_u8 {
        info!(
            "{}: [{:?}]",
            i,
            GLOBAL_HOLDER.with(|h| h.borrow_mut().next())
        );
    }

    Ok(())
}

#[derive(Debug, Clone, Default)]
pub struct User {
    name: String,
    age: usize,
}

pub struct Holder(User);

impl Iterator for Holder {
    type Item = User;

    fn next(&mut self) -> Option<Self::Item> {
        self.0.age += 1;
        Some(self.0.clone())
    }
}
